package com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.yadiudiu.house.MyActivity.PaymentActivity;
import com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.CleanBusiness;

import org.xutils.common.Callback;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

import static com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity.CreditTutorialActivity.GO_DETAIL;

/**
 * Created by Administrator on 2017/8/22.
 * 信贷详情
 */

public class DetailsCreditActivity extends Activity implements View.OnClickListener {
    @Bind(R.id.retur)
    LinearLayout retur;
    Context context;
    @Bind(R.id.check_out_more)
    TextView checkOutMore;
    @Bind(R.id.headings)
    TextView mName;
    @Bind(R.id.time)
    TextView mTime;
    @Bind(R.id.positioning_text)
    TextView mWatch;
    @Bind(R.id.browse_text)
    TextView mOpen;
    @Bind(R.id.list_view)
    ListView mListView;
    private CreditTutorialBean mBean;
    private List<CreditDetailBean> mDetailBean;
    private DetailsCreditAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details_credit);
        ButterKnife.bind(this);
        context = this;
        initView();
    }

    private void initView() {
        mBean = (CreditTutorialBean) getIntent().getSerializableExtra(GO_DETAIL);
        if (mBean != null) {
            LoadHeaderData();
        }
        retur.setOnClickListener(this);
        checkOutMore.setOnClickListener(this);
    }

    private void LoadHeaderData() {
        mName.setText(mBean.credit_title);
        mTime.setText(mBean.add_time);
        mWatch.setText(mBean.watch);
        mOpen.setText(mBean.paycount);
        initData();
    }

    private void initData() {
        CleanBusiness.getCreditDetail(new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                mDetailBean = CleanBusiness.parseToCreditDetailBean(result);
                if (mDetailBean != null && mDetailBean.size() > 0) {
                    mAdapter = new DetailsCreditAdapter(DetailsCreditActivity.this, mDetailBean);
                    mListView.setAdapter(mAdapter);
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.retur:
                finish();
                break;
            case R.id.check_out_more:
                startActivity(new Intent(DetailsCreditActivity.this, PaymentActivity.class));
                break;
        }
    }
}




